<template>
  <div class="createPost-main-container-tender">
    <div v-show="show_disable_write">
      <el-divider
        style="margin: 20px"
      ><span
        style="color: #666; font-size: 12px"
      >以下为当前项目待投标信息</span></el-divider>
      <el-form
        ref="submitFrom"
        style="margin-top: 20px"
        :model="submitFrom"
        label-position="right"
        class="form-container"
      >
        <el-form-item
          class="guarantee"
          style="margin-bottom: 10px"
          label-width="130px"
          label="是否投标:"
        >
          <el-radio-group
            v-model="submitFrom.stay_tender_status"
            @change="isTender(submitFrom.stay_tender_status)"
          >
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="2">否</el-radio-button>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <el-form
        v-show="!is_tender_form"
        ref="submitFrom"
        :model="submitFrom"
        label-position="right"
        class="form-container"
      >
        <el-form-item
          style="margin-bottom: 10px"
          label-width="130px"
          label="弃标原因:"
        >
          <el-input
            v-model="submitFrom.discard_resonse"
            :rows="1"
            type="textarea"
            autosize
            placeholder="如:废弃原因,必填"
          />
        </el-form-item>
      </el-form>

      <el-form
        v-show="is_tender_form"
        ref="submitFrom"
        :model="submitFrom"
        label-position="right"
        class="form-container"
      >
        <el-row :gutter="24">
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="分公司标书负责人:"
            >
              <el-input
                v-model="submitFrom.person_tender"
                :rows="1"
                type="textarea"
                autosize
                placeholder="不可输入数字"
              /> </el-form-item></el-col>
          <el-col :span="13">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="联系方式:"
            >
              <el-input
                v-model="submitFrom.person_tender_mobile"
                :rows="1"
                type="textarea"
                autosize
                placeholder="请输入正确的联系方式"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item
          class="guarantee"
          style="margin-bottom: 10px"
          label-width="130px"
          label="需要投标保证金:"
        >
          <el-radio-group
            v-model="submitFrom.guarantee_money"
            @change="isGuaranteeMoney(submitFrom.guarantee_money)"
          >
            <el-radio-button :label="1">是</el-radio-button>
            <el-radio-button :label="2">否</el-radio-button>
          </el-radio-group>
        </el-form-item>

        <el-form-item
          v-show="is_guarantee_money"
          style="margin-bottom: 10px"
          label-width="130px"
          label="支付方式:"
        >
          <el-input
            v-model="submitFrom.payment_method"
            :rows="1"
            type="textarea"
            autosize
            placeholder="如:现金"
          />
        </el-form-item>

        <el-form-item
          v-show="is_guarantee_money"
          style="margin-bottom: 10px"
          label-width="130px"
          label="支付金额(万元):"
        >
          <el-input
            v-model="submitFrom.payment_money"
            :rows="1"
            type="textarea"
            autosize
            placeholder="如:100"
          />
        </el-form-item>

        <el-form-item
          v-show="is_guarantee_money"
          style="margin-bottom: 10px"
          label-width="130px"
          label="收款方名称:"
        >
          <el-input
            v-model="submitFrom.payee_name"
            :rows="1"
            type="textarea"
            autosize
            placeholder="如:xxxx公司"
          />
        </el-form-item>
        <el-form-item
          v-show="is_guarantee_money"
          style="margin-bottom: 10px"
          label-width="130px"
          label="开户银行:"
        >
          <el-input
            v-model="submitFrom.bank_deposit"
            :rows="1"
            type="textarea"
            autosize
            placeholder="如:xxxx银行"
          />
        </el-form-item>
        <el-form-item
          v-show="is_guarantee_money"
          style="margin-bottom: 10px"
          label-width="130px"
          label="开户账号:"
        >
          <el-input
            v-model="submitFrom.account_number"
            :rows="1"
            type="textarea"
            autosize
            placeholder="请输入正确的开户账号"
          />
        </el-form-item>

        <el-form-item
          style="margin-bottom: 10px"
          label-width="130px"
          label="资料清单:"
        >
          <el-input
            v-model="submitFrom.information_list"
            type="textarea"
            :autosize="{ minRows: 4, maxRows: 10 }"
            placeholder="请输入资料清单"
          />
        </el-form-item>
      </el-form>

      <div
        class="footer"
        style="width: 100%; text-align: center; padding: 10px"
      >
        <el-button
          style="margin-left: 10px; border: 1px silid red"
          type="success"
          @click="submit"
        >提交</el-button>
        <router-link :to="'/project/index'">
          <el-button
            style="margin-left: 30px"
            size="medium"
            type="default"
          >返回</el-button>
        </router-link>
      </div>
    </div>
    <div
      v-show="show_disable"
      style="margin-top: 30px"
      class="createPost-main-container-tender"
    >
      <el-divider
        style="margin: 20px"
      ><span
        style="color: #666; font-size: 12px"
      >以下为当前项目待投标信息</span></el-divider>
      <el-form
        ref="submitFrom"
        style="margin-top: 10px"
        :model="submitFrom"
        label-position="right"
        class="form-container"
      >
        <el-form-item
          style="margin-bottom: 10px"
          label-width="130px"
          label="是否投标:"
        >
          <span
            v-if="submitFrom.stay_tender_status == '1'"
            style="color: rgb(19, 206, 102); font-size: 16px"
          >是</span>
          <span v-else style="color: red; font-size: 16px">否</span>
        </el-form-item></el-form>

      <el-form
        ref="submitFrom"
        :model="submitFrom"
        label-position="right"
        class="form-container"
      >
        <el-row v-show="submitFrom.stay_tender_status == '1'" :gutter="24">
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="分公司标书负责人:"
            >
              <span>{{ submitFrom.person_tender }}</span>
            </el-form-item></el-col>
          <el-col :span="13">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="联系方式:"
            >
              <span>{{ submitFrom.person_tender_mobile }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form
          ref="submitFrom"
          :model="submitFrom"
          label-position="right"
          class="form-container"
        >
          <el-form-item
            v-show="submitFrom.stay_tender_status == '1'"
            style="margin-bottom: 10px"
            label-width="130px"
            label="需要投标保障金:"
          >
            <span
              v-if="submitFrom.guarantee_money == '1'"
              style="color: rgb(19, 206, 102); font-size: 16px"
            >是</span>
            <span v-else style="color: red; font-size: 16px">否</span>
          </el-form-item></el-form>

        <el-row
          v-show="
            submitFrom.stay_tender_status == '1' &&
              submitFrom.guarantee_money == '1'
          "
          :gutter="24"
        >
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="支付方式:"
            >
              <span>{{ submitFrom.payment_method }}</span>
            </el-form-item></el-col>
        </el-row>

        <el-row
          v-show="
            submitFrom.stay_tender_status == '1' &&
              submitFrom.guarantee_money == '1'
          "
          :gutter="24"
        >
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="支付金额(万元):"
            >
              <span>{{ submitFrom.payment_money }}</span>
            </el-form-item></el-col>
        </el-row>

        <el-row
          v-show="
            submitFrom.stay_tender_status == '1' &&
              submitFrom.guarantee_money == '1'
          "
          :gutter="24"
        >
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="收款方名称:"
            >
              <span>{{ submitFrom.payee_name }}</span>
            </el-form-item></el-col>
        </el-row>
        <el-row
          v-show="
            submitFrom.stay_tender_status == '1' &&
              submitFrom.guarantee_money == '1'
          "
          :gutter="24"
        >
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="开户银行:"
            >
              <span>{{ submitFrom.bank_deposit }}</span>
            </el-form-item></el-col>
        </el-row>
        <el-row
          v-show="
            submitFrom.stay_tender_status == '1' &&
              submitFrom.guarantee_money == '1'
          "
          :gutter="24"
        >
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="开户账号:"
            >
              <span>{{ submitFrom.account_number }}</span>
            </el-form-item></el-col>
        </el-row>
        <el-row v-show="submitFrom.stay_tender_status == '2'" :gutter="24">
          <el-col :span="11">
            <el-form-item
              style="margin-bottom: 10px"
              label-width="130px"
              label="弃标原因:"
            >
              <span>{{ submitFrom.discard_resonse }}</span>
            </el-form-item></el-col>
        </el-row>

        <el-form-item
          v-show="submitFrom.stay_tender_status == '1'"
          label-width="130px"
          label="资料清单:"
          style="margin-bottom: 10px"
        >
          <el-input
            v-model="submitFrom.information_list"
            :rows="1"
            :disabled="true"
            type="textarea"
            autosize
            placeholder="无"
          />
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import {
  getProjectDetail,
  insertFile,
  insertStayTenderInfo
} from '@/api/project'
import { getToken } from '@/utils/auth'
import { getInfo } from '@/api/user'
import { analysisExcel } from '@/api/folder'
// 需要的表单
const formSubmit = {
  stay_tender_status: '', // 是否中标
  person_tender: '', // 分公司标书负责人
  person_tender_mobile: '', // 联系方式
  payment_method: '', // 支付方式
  payment_money: '', // 支付金额
  payee_name: '', // 收款方名称
  bank_deposit: '', // 开户银行
  discard_resonse: '', // 弃标原因
  account_number: '', // 开户账号
  information_list: '', // 资料清单
  guarantee_money: '' // 是否需要投标保障金
}
// http://dc.tuobao.m.com/storage/images
export default {
  name: 'ArticleDetail',
  props: {
    is_stay_tender: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      id: '', // 当前项目的id
      submitFrom: Object.assign({}, formSubmit),
      username: '',
      is_tender_form: true,
      value: '',
      valueDisOne: false,
      valueDisTwo: false,
      file_new_names: {},
      uploadFileDialog: false,
      displayForm: false,
      show_disable: false, // 判断是否已经填写待投标信息
      show_disable_write: false, // 判断是否已经填写待投标信息
      is_guarantee_money: false // 判断是否已经填写待投标信息
    }
  },
  created() {
    if (this.is_stay_tender) {
      const value = this.$route.query.value
      const status = this.$route.query.status
      const id = this.$route.query && this.$route.query.id
      //   let update = this.$route.query.update;
      if (value == '1') {
        if (status != 0 && status != 1 && status != 2 && status != 8) {
          this.show_disable = true
          //   this.show_disable_write = false
          this.getProjectData(id)
        }
      }
      if (value == '8') {
        this.show_disable_write = true
        //   this.submitFrom.stay_tender_status = 1
      }

      this.id = id
      this.getUserInfo()
    }
  },
  methods: {
    isTender(value) {
      if (value == '1') {
        this.is_tender_form = true
      } else {
        this.is_tender_form = false
      }
    },

    isGuaranteeMoney(value) {
      if (value == '1') {
        this.is_guarantee_money = true
      } else {
        this.is_guarantee_money = false
      }
    },

    // 发布
    submit() {
      new Promise((resolve, reject) => {
        insertStayTenderInfo({
          id: this.id,
          submitFrom: this.submitFrom
        }).then(() => {
          this.$message({
            type: 'success',
            message: '填写成功!'
          })
          this.$router.push('/project/index')
        })
      })
    },
    // 获取项目
    getProjectData(id) {
      new Promise((reslove, reject) => {
        getProjectDetail({ id: id }).then((response) => {
          this.submitFrom = response.data
          // console.log("当前项目状态" + response.data.project_status);
          //   if (this.submitFrom.tender_status == "1") {
          //     this.is_tender_form = true;
          //   } else {
          //     this.is_tender_form = false;
          //   }
          //   for (let i = 0; i < this.submitFrom.file_path.length; i++) {
          //     if (this.submitFrom.file_path[i].type == "0") {
          //       if (
          //         this.submitFrom.file_path[i].fileType == "png" ||
          //         this.submitFrom.file_path[i].fileType == "jpeg" ||
          //         this.submitFrom.file_path[i].fileType == "jpg"
          //       ) {
          //         this.file_list.push({
          //           name: this.submitFrom.file_path[i].file_name,
          //           url: this.submitFrom.file_path[i].file_path,
          //           urls: this.submitFrom.file_path[i].file_path,
          //           fileType: this.submitFrom.file_path[i].fileType,
          //         });
          //       } else {
          //         this.file_list.push({
          //           name: this.submitFrom.file_path[i].file_name,
          //           url: this.submitFrom.file_path[i].file_path,
          //           urls: this.getIconUrl(this.submitFrom.file_path[i].fileType),
          //           fileType: this.submitFrom.file_path[i].fileType,
          //         });
          //       }
          //     }
          //   }
          //   this.submitFrom.file_path = this.file_list;
        })
      })
    },

    // 获取当前用户的登录信息
    getUserInfo() {
      new Promise((resolve, reject) => {
        getInfo().then((response) => {
          this.username = response.data.name // 当前登录用户的姓名
        })
      })
    }
  }
}
</script>
<style>
.createPost-main-container-tender {
  padding: 0px 45px 0px 50px;
}
.createPost-main-container-tender .el-form-item--medium .el-form-item__content {
  line-height: 25px;
}
.createPost-main-container-tender .el-form-item--medium .el-form-item__label {
  line-height: 25px;
}
.createPost-main-container-tender .imgBox {
  position: relative;
}
.createPost-main-container-tender .imgBox .btnDelete {
  width: 14px;
  height: 14px;
  background: rgb(146, 145, 145);
  border: 0px none;
  /* border-radius: 1px; */
  position: absolute;
  float: right;
  text-align: center;
  line-height: 14px;
  top: 0px;
  right: 0px;
  display: block;
}

.createPost-main-container-tender .container {
  /* width: 100%; */
  /* margin: 10px; */
  /* border: 1px solid red; */
  display: grid;
  grid-row-gap: 20px;
  grid-column-gap: 20px;
  grid-template-columns: repeat(auto-fill, 100px);
  /* grid-template-rows: repeat(auto-fill, 100px); */
}

.createPost-main-container-tender .container .box {
  /* border: 1px solid red; */
  width: 112px;
  height: 136px;
  /* margin: 5px; */
  padding: 10%;
}

.createPost-main-container-tender .container .box .iconBox {
  width: 100%;
  height: 80px;
  text-align: center;
  position: relative;
}
.createPost-main-container-tender .container .box .iconBox .btnDelete {
  width: 14px;
  height: 14px;
  background: rgb(146, 145, 145);
  border: 0px none;
  /* border-radius: 1px; */
  position: absolute;
  float: right;
  text-align: center;
  line-height: 14px;
  top: 0px;
  right: 0px;
  display: block;
}
.createPost-main-container-tender .container .box .iconBox .btnDelete::after {
  content: "X";
  font-size: 16px;
  color: #fff;
  /* border: 1px solid red; */
}

.createPost-main-container-tender .container .box .fileText {
  width: 100%;
  margin-top: 10px;
  text-align: center;
  height: 23px;
  line-height: 23px;
  color: #595c5f;
  font-size: 15px;
}
.createPost-main-container-tender .active {
  background: #eff3f9 none repeat scroll 0 0;
  border-color: #bcccde;
  border-radius: 10px;
}
/* .createPost-main-container-tender .el-textarea__inner {
  padding: 0px 0px;
  resize: none;
} */
.createPost-main-container-tender .el-textarea.is-disabled .el-textarea__inner {
  background: #fff;
  color: #000;
  border: none;
  padding: 0px 0px;
  resize: none;
}
.createPost-main-container-tender .guarantee {
  display: flex;
  align-items: center;
}
.createPost-main-container-tender .guarantee .el-form-item__content {
  margin-left: 0 !important;
}
</style>
